/*
 * @Description: 全宗信息面板
 * @Author: Rfan
 * @Date: 2022-03-29 13:57:08
 * @LastEditTime: 2022-05-25 08:57:06
 */

import type { FC } from 'react';
import classNames from 'classnames/bind';
import { Button, Space, Table } from 'antd';
import { useRightApproveContext } from '../../contexts/RightApproveContext';
import { useFormatMessage } from '@/utils/intlHelpers';

import styles from '../../styles/list.module.scss';

const cx = classNames.bind(styles);

const { Column } = Table;

export type BorrowListProps = {
  title?: string;
  data?: any;
};

const BorrowList: FC<BorrowListProps> = ({ title, data }) => {
  console.log('sort pane:', data);
  const formatMessage = useFormatMessage();
  const { list, loading, selectItems } = useRightApproveContext();

  const showEditModal = (data: any): void => {
    // showEditDialog(data);
  };

  // 表格选项相关设置
  const onSelectChange = (selectedRowKeys: number[]): void => {
    console.log('selectedRowKeys changed: ', selectedRowKeys);
  };

  const rowSelection = {
    selectItems,
    onChange: onSelectChange
  };

  return (
    <div className={cx('approve-list')}>
      <Table dataSource={list || []} loading={loading} rowKey="id" rowSelection={rowSelection}>
        <Column title="序号" dataIndex="id" key="id" align="center" />
        <Column title="借阅编号" dataIndex="code" key="code" align="center" />
        <Column title="申请人" dataIndex="operateTime" key="operateTime" align="center" />
        <Column title="申请部门" dataIndex="name" key="name" align="center" />
        <Column title="借阅目的" dataIndex="name" key="name" align="center" />
        <Column title="数量" dataIndex="operateTime" key="operateTime" align="center" />
        <Column title="借阅状态" dataIndex="operateTime" key="operateTime" align="center" />
        <Column title="登记日期" dataIndex="operateTime" key="operateTime" align="center" />
        <Column title="归还日期" dataIndex="operateTime" key="operateTime" align="center" />
        <Column
          title={formatMessage('tableAction')}
          key="action"
          align="center"
          render={(_text, record: any) => (
            <Space>
              <Button
                type="link"
                onClick={() => {
                  showEditModal(record);
                }}
              >
                详情
              </Button>
            </Space>
          )}
        />
      </Table>
    </div>
  );
};

export default BorrowList;
